package db;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import model.Room;
import model.RoomReservation;

public class DbRRBuffer {
	private Connection con;
	
	public DbRRBuffer() {
		con = DbConnection.getInstance().getDBcon();
	}
	
	public int insertBuffer(RoomReservation res, Room room) throws Exception {
		 //call to get the next ssn number
	    

	   int rc = -1;
	   String query="INSERT INTO RRbuffer(RResId, RoomId)  VALUES('"+
	  		res.getId() + "','"  +
		    
            room.getId() + "')";
	        
	        
	                 

	   System.out.println("insert : " + query);
	  try{ // insert new employee +  dependent
	      Statement stmt = con.createStatement();
	      stmt.setQueryTimeout(5);
	      System.out.println(query);
	 	  rc = stmt.executeUpdate(query);
	      stmt.close();
	  }//end try
	   catch(SQLException ex){
	      System.out.println("Order ikke oprettet");
	      System.out.println("SQLException says: " + ex.getMessage());
	     throw new Exception ("Order is not inserted correct");
	   }
	   return(rc);
	}

}
